import { createStore } from 'vuex'
import { foodData, Food } from '@/data/foodData'

// 定义 Vuex 状态接口
interface State {
  foods: Food[];
}

// 创建 Vuex store
export const store = createStore<State>({
  state: {
    // 初始化状态为 foodData 假数据
    foods: foodData
  },
  getters: {
    // 获取所有食物数据
    allFoods (state): Food[] {
      return state.foods
    },
    // 根据 author 获取食物数据
    getFoodsByAuthor: (state) => (accessories: string): Food[] => {
      return state.foods.filter(food => food.accessories === accessories)
    }
  },
  mutations: {
  },
  actions: {
  }
})
